package com.lc.context;

import com.lc.config.annos.Exclude;

/**
 * @author liuc
 * @date 2021/4/18
 * @description
 **/
@Exclude
public class AnnoApplicationContext implements ApplicationContext{

    private BeanFactory beanFactory;
    private String[] pkgs = new String[1];

    public AnnoApplicationContext(String pkg){
        //todo 解析配置类
        beanFactory = new BeanFactory();
        pkgs[0] = pkg;
    }

    /**
     * get bean by id
     * @param id
     * @return
     */
    @Override
    public Object getBean(String id) {
        return beanFactory.getBean(id);
    }

    /**
     * get bean by type
     * @param clz
     * @param <T>
     * @return
     */
    @Override
    public <T> T getBean(Class<T> clz) {
        return (T) beanFactory.getBean(clz);
    }

    @Override
    public void refresh(){
        beanFactory.setPackages(pkgs);
    }
}
